#ifndef _POINTSET_H_
#define _POINTSET_H_

#include <cstdio>
#include <cmath>

class PointSet
{
public:
	PointSet();
	virtual ~PointSet();

	void getBound(float &xmin, float &xmax, float &ymin, float &ymax, float &zmin, float &zmax) const;
  bool addPoint(float x, float y, float z, float nx, float ny, float nz);

  float getNormalX(int index) const { return normal[index][0]; };
  float getNormalY(int index) const { return normal[index][1]; };
  float getNormalZ(int index) const { return normal[index][2]; };
  const float* getNormal(int index) const { return normal[index]; };
  float getPointX(int index) const { return point[index][0]; };
  float getPointY(int index) const { return point[index][1]; };
  float getPointZ(int index) const { return point[index][2]; };
  const float* getPoint(int index) const { return point[index]; };
	void allocateStorage(int n);
  int getNumberPoints() const { return point_N; };
  int getAllocatedStorage() const { return storage_N; };

  bool isQuad() const { return bIsQuad; };
  bool isInPointSet(float x, float y, float z);
  void setQuad() { bIsQuad = true; };
  float getQuadX(int index) const { return quad[index][0]; };
  float getQuadY(int index) const { return quad[index][1]; };
  float getQuadZ(int index) const { return quad[index][2]; };
  void setQuadX(int index, float value) { quad[index][0] = value; };
  void setQuadY(int index, float value) { quad[index][1] = value; };
  void setQuadZ(int index, float value) { quad[index][2] = value; };
  float getTangent1X(int index) const { return tangent1[index][0]; };
  float getTangent1Y(int index) const { return tangent1[index][1]; };
  float getTangent1Z(int index) const { return tangent1[index][2]; };
  void setTangent1X(int index, float value) { tangent1[index][0] = value; };
  void setTangent1Y(int index, float value) { tangent1[index][1] = value; };
  void setTangent1Z(int index, float value) { tangent1[index][2] = value; };
  float getTangent2X(int index) const { return tangent2[index][0]; };
  float getTangent2Y(int index) const { return tangent2[index][1]; };
  float getTangent2Z(int index) const { return tangent2[index][2]; };
  void setTangent2X(int index, float value) { tangent2[index][0] = value; };
  void setTangent2Y(int index, float value) { tangent2[index][1] = value; };
  void setTangent2Z(int index, float value) { tangent2[index][2] = value; };
  const float* getTangent1(int index) const { return tangent1[index]; };
  const float* getTangent2(int index) const { return tangent2[index]; };

private:  
  inline bool equal(float a, float b)
  {
    if (fabs(a - b) < 0.00001)
      return true;
    else
      return false;
  };

  bool bIsQuad;
	int point_N, storage_N;

  float (*point)[3];
  float (*normal)[3];
	float (*quad)[3];
	float (*tangent1)[3];
	float (*tangent2)[3];
};

#endif
